from threading import Thread
import time

dantalanzi=0

class sell(Thread):
    worker = ""
    gongzi=0
    tm=0
    count=0

    def run(self) -> None:
        global dantalanzi
        while True:
            if  dantalanzi < 500:
                self.count=self.count+1
                dantalanzi = dantalanzi + 1
                print("现在篮子里有",dantalanzi,"个蛋挞",self.worker,"做了",self.count,"个蛋挞工资为",self.gongzi)
                self.gongzi=self.gongzi+1.5
                time.sleep(self.tm)
            elif dantalanzi ==500:
                time.sleep(3)
                continue
class buy(Thread):
    user=""
    count=0
    money=0
    def run(self) -> None:
        global dantalanzi
        while True:
            if self.money >= 3:
                if dantalanzi > 0:
                    self.count = self.count + 1
                    dantalanzi = dantalanzi - 1
                    self.money = self.money - 3
                    print("现在篮子里有", dantalanzi, "个蛋挞")

                else:
                    time.sleep(2)
                    continue
            else:
                print(self.user, "买了", self.count, "个蛋挞", "还有",money,"元")
                break



s1=sell()
s2=sell()
s3=sell()

b1=buy()
b2=buy()
b3=buy()
b4=buy()
b5=buy()
b6=buy()

s1.worker="张三"
s1.tm=0.1
s1.gongzi=0
s1.count=0
s2.worker="李四"
s2.worker=0.2
s2.gongzi=0
s2.count=0
s3.worker="王五"
s3.tm=0.3
s3.gongzi=0
s3.count=0

b1.user="小明"
b1.count=0
b1.money=30000
b2.user="小红"
b2.count=0
b2.money=30000
b3.user="小刚"
b3.count=0
b3.money=30000
b4.user="小胖"
b4.count=0
b4.money=30000
b5.user="小肠"
b5.count=0
b5.money=30000
b6.user="小腿"
b6.count=0
b6.money=30000

s1.start()
s2.start()
s3.start()

b1.start()
b2.start()
b3.start()
b4.start()
b5.start()
b6.start()




